package logic

import (
	"context"
	"video-joy/userrpc/userrpc"

	"video-joy/api/internal/svc"
	"video-joy/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePwdLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdatePwdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePwdLogic {
	return &UpdatePwdLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatePwdLogic) UpdatePwd(req *types.UpdatePwdRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.UserRpc.UpdatePwd(l.ctx, &userrpc.UpdatePwdRequest{
		PhoneNum:  req.PhoneNum,
		NewPwd:    req.NewPwd,
		AckNewPwd: req.AckNewPwd,
		SmsCode:   req.SmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "重置密码成功",
		Code:    200,
		Data:    update,
	}, nil

}
